Skip to content

Picnic as second supermarket (search + mapping, no checkout) - #452

Merged
adri merged 12 commits into
masterfrom
adri/picnic-adapter
Oct 18, 2026
Merged

adri merged 12 commits into
masterfrom
adri/picnic-adapter

Conversation

@adri

@adri adri commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Adds Picnic as a second supermarket next to Albert Heijn: AH ordering is down after the cyber incident, so the plan can now sync into the Picnic cart instead. @adri

What changed

  • New Picape.Picnic client for Picnic's api/15: search, reading the cart, adding and removing products. Modelled on the Picnic client this app carried before it moved to AH.
  • A third mode next to ah and checklist: picnic. set_mode accepts it; in picnic mode the plan syncs into the Picnic cart for every mapped ingredient. Unplanned products come out, a remap takes the old product out, and the cart is re-read before each sync.
  • Ingredients without a Picnic mapping show up as checklist items and check_item ticks them, in picnic mode too.
  • A dead Picnic or a rejected auth key falls back to the checklist the same way a dead supermarket does in ah mode, with supermarket_reachable false.
  • The whole app follows the selected store: MCP search_supermarket hits Picnic in picnic mode, GraphQL has searchPicnic, the cart screen switches between AH, Picnic and checklist, and the ingredient screens pick or clear the Picnic product without touching the AH id. Adding an ingredient accepts a Picnic selling unit id on its own.
  • Order items and get_shopping_list report store per item (ah, picnic, checklist).
  • AH is untouched: no code renamed or replaced, all product ids and replacement mappings are as they were, and picnic sync never writes to the AH basket.
  • Recipes, plans, history and cooked status stay supermarket-independent. Picnic order snapshots are not stored: order_item.product_id is numeric and Picnic selling unit ids are strings, so a closed picnic order keeps its plan rows like pre-snapshot orders did.

Migrations

One additive migration: 20261018120000_add_ingredient_picnic_product adds picnic_product_id (string, unique index) and picnic_product_raw (jsonb) to recipe_ingredient. No drops, no renames, no data rewrites.

MCP tools

  • search_supermarket — searches the active store: Picnic in picnic mode, the supermarket otherwise.
  • search_picnic — search the Picnic catalogue explicitly, returns selling unit ids like s1016186 with name, price in cents, unit quantity and image id.
  • map_ingredient_picnic — set or clear an ingredient's Picnic product and cache name/unit/image/price.
  • get_shopping_list — reports mode and store per item.
  • set_mode — accepts ah, picnic and checklist.
  • check_item — works in checklist and picnic mode.

Auth

  • There is no username, password or SMS login. PICNIC_AUTH_KEY carries the x-picnic-auth value the Picnic app itself sends on every request, taken from an app session.
  • A capture of that session shows no login or refresh call: the storefront api carries one long-lived x-picnic-auth on every request and never rotates it. Picape therefore uses the configured key directly and has no refresh-token code. When Picnic rejects the key the calls fail and the list falls back to the checklist until a fresh key is configured.

Environment

  • PICNIC_AUTH_KEY — required for picnic mode; the x-picnic-auth value every call sends.
  • PICNIC_BASE_URL, PICNIC_AGENT, PICNIC_DID, PICNIC_USER_AGENT — optional, defaulted (PICNIC_DID gets a generated id per boot).

No checkout

There is no checkout, order placement, payment, confirmation or delivery-slot code anywhere in this change, and none is planned here. Ordering finishes in the Picnic app; Picape only keeps the cart in step with the plan. After checking out in the Picnic app, tap "Bestelling ontvangen" in Picape to close the order; Picape cannot see a Picnic checkout by itself.

Tests

  • mix check: green — format, credo --strict, compile --warnings-as-errors, 173 tests, sobelow.
  • cd frontend && npm run check: green (ESLint, Prettier, GraphQL schema check, Jest).
  • bin/e2e: 95 passed, 10 pre-existing platform skips. The shop baseline changed on purpose: the store switch shows where it used to link to the checklist.
  • New tests cover the client against the supermarket fake (which serves the api/15 routes and logs every request with its headers), the mapping, the mode switch, the checklist fallback, a rejected auth key and a dead Picnic. Fixtures are hand-written with fake values.

Not verified without live Picnic credentials: whether the api/15 endpoints and the x-picnic-auth flow still answer exactly the way the client and the fake assume.

Follow-ups (pre-existing on master, not fixed here)

  • &1 + 2 in ordered_item_quantities double-counts a planned recipe's ingredients.
  • The AH Plug.Conn.Query.encode use builds a wrong request query.
  • In picnic mode Picape cannot see a Picnic checkout; a read-only delivery summary would let "Bestelling ontvangen" happen by itself.

Screenshots

Store switch in picnic mode

Picnic product picker

adri and others added 12 commits October 18, 2026 11:38
Each ingredient gets an optional picnic_product_id plus a raw cache of
the product behind it, stored next to the AH mapping it already has.
The migration only adds columns and an index, so existing rows and AH
mappings stay exactly as they are.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
HTTP client for Picnic's api/15, modelled on the Picnic client the app
carried before it moved to AH. It covers search, reading the cart and
adding or removing products in it. There is no checkout, payment or
delivery-slot call on purpose: orders finish in the Picnic app.

The auth key comes from PICNIC_AUTH_KEY through runtime config, the
same way the supermarket's secrets are handled.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
set_mode now accepts picnic next to ah and checklist. In picnic mode
the plan syncs into the Picnic cart for every mapped ingredient and
the unmapped rest shows up as checklist items that check_item can
tick. A dead Picnic falls back to the checklist the same way a dead
supermarket does in ah mode. Order items carry which store they come
from. The AH code path is unchanged: picnic sync only writes to the
Picnic cart and never touches the basket, the AH mappings or an
order snapshot.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The fake answers the api/15 routes picnic mode uses: reading the cart,
adding and removing products, search and login. It keeps a cart the
same way it keeps the AH basket so tests can assert on what sync
pushed. The fixtures are hand-written with fake ids and fake image
hashes.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Two new tools: search_picnic finds products in the Picnic catalogue,
map_ingredient_picnic sets or clears the Picnic product behind an
ingredient and caches the name, unit, image and price of a search
result. get_shopping_list reports store per item and the ingredient
lookup resolves both key spaces, so a picnic cart row and a checklist
fallback row both find their ingredient. The order item type gains
store, the ingredient type gains picnic_product_id, and set_mode and
check_item describe the new mode.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The client tests run against the supermarket fake: search, reading
and mutating the cart, and the delta math apply_changes turns a
target-quantity diff into. The mode tests cover switching between ah,
picnic and checklist, the checklist fallback for unmapped
ingredients, ticking, removing with quantity 0, and that a picnic
sync leaves the AH basket and the AH mappings untouched.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The MCP README names the two new tools, explains store per item and
says Picape never checks out at Picnic. The credentials line in
AGENTS.md names the PICNIC_* env vars without their values.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
A non-2xx answer or an error body from Picnic was cached as the cart,
so a rejected auth key looked like an empty reachable cart. Responses
now raise the shared supermarket error instead, and the client refuses
to call out at all while PICNIC_AUTH_KEY is unset.

Unplanned recipes now count at quantity 0, like the supermarket path,
so unplanning removes products from the Picnic cart. Sync also drops
the five-hour cart cache before it computes deltas, so it diffs
against the cart Picnic actually has.

The search URL encoded the term with Plug.Conn.Query, which produces
"=term" rather than "search_term=term"; the fake now requires the
parameter so that shape cannot come back. The fake also logs every
request for header assertions and can answer 401 AUTH_ERROR on the
api/15 routes.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
login/2 now reads the second_factor_authentication_required flag in
the body instead of guessing from a missing header, and returns the
provisional key so generate_2fa/1 and verify_2fa/2 can finish the
login against /user/2fa/generate and /user/2fa/verify. mix
picnic.login runs the whole flow and stores the key in
config/dev.secret.exs, printing only "ok" so the key never lands in
terminal output.

Headers Picnic expects got non-empty defaults matching
python-picnic-api2, including x-picnic-country: NL, and empty
configured values now count as unset.

picnic_quantities sums rows per selling unit because the cart can
list one on two ORDER_LINE groups. item_ingredient_ids maps the
checklist rows picnic mode falls back to by their supermarket product
id, the way the rest of the app reads them.

add_ingredient accepts a Picnic product without a supermarket
product, skipping the product fetch there is none of. README and the
MCP descriptions say "Bestelling ontvangen" closes a Picnic order
after checkout in the Picnic app.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Searches, pickers and the list all read the order's store now:

- search_supermarket on MCP follows the mode, so it hits Picnic in
  picnic mode; search_picnic stays the explicit variant. GraphQL gets
  a searchPicnic query for the same catalogue.
- The cart screen switches between AH, Picnic and the checklist and
  shows which store is active. Picnic-mode items that stayed on the
  checklist get tick boxes there too.
- Ingredient screens pick or clear the Picnic product without
  touching the AH id, and adding an ingredient accepts a Picnic
  selling unit id on its own. A remap takes the old product out of
  the Picnic cart, since Picnic keys its cart by selling unit.
- Picnic product ids must look like s123; search results fall back
  to price_ranges when a tile carries no display_price.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Adrian authenticates Picape with the x-picnic-auth value his own Picnic
app session sends, not with a username, password or SMS code. The
capture of that session shows no login or refresh call: the storefront
api carries one long-lived x-picnic-auth on every request. So
PICNIC_AUTH_KEY stays a direct access token, and login/2, the 2FA
calls, the mix picnic.login task and the fake endpoints go away.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Prod carries a leftover index named
recipe_ingredient_picnic_product_id_index on supermarket_product_id
from a column rename. That is also the default name Ecto picks for a
unique index on picnic_product_id, so the migration would fail on
release with a name collision. Give it an explicit name and point the
changeset constraints at it. A regression test recreates the leftover
index on a scratch test database and runs the real migration over it.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@adri
adri marked this pull request as ready for review October 18, 2026 12:55
@adri
adri merged commit bb5184c into master Oct 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant